package com.qunar.dyds.entity;

import java.io.Serializable;
import java.util.Date;

import com.qunar.base.meerkat.util.HashUtil;
import com.qunar.base.meerkat.util.StringUtil;

/**
 * 选手信息
 */
public class Competitor implements Serializable {

    private static final long serialVersionUID = -8401243315020407940L;

    /**
     * 编号
     */
    private Integer id;
    /**
     * 姓名
     */
    private String name;

    /**
     * 年龄
     */
    private Integer age;

    /**
     * 学校
     */
    private String school;

    /**
     * 专业
     */
    private String major;

    /**
     * 年级
     */
    private String grade;

    /**
     * 电话
     */
    private String mobile;

    /**
     * 邮件
     */
    private String email;

    /**
     * 登陆名
     */
    private String username;

    /**
     * 密码
     */
    private String password;

    /**
     * 头像地址
     */
    private String avatar;

    /**
     * 简介
     */
    private String comment;

    /**
     * 报名号
     */
    private String inviteCode;

    /**
     * 投票数
     */
    private Integer voteCount;

    /**
     * 状态
     */
    private Integer status;

    /**
     * 注册时间
     */
    private Date created;

    /**
     * 更新时间
     */
    private Date updated;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSchool() {
        return school;
    }

    public void setSchool(String school) {
        this.school = school;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getMajor() {
        return major;
    }

    public void setMajor(String major) {
        this.major = major;
    }

    public String getGrade() {
        return grade;
    }

    public void setGrade(String grade) {
        this.grade = grade;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public String getInviteCode() {
        return inviteCode;
    }

    public void setInviteCode(String inviteCode) {
        this.inviteCode = inviteCode;
    }

    public Integer getVoteCount() {
        return voteCount;
    }

    public void setVoteCount(Integer voteCount) {
        this.voteCount = voteCount;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    public Date getUpdated() {
        return updated;
    }

    public void setUpdated(Date updated) {
        this.updated = updated;
    }

    /**
     * 生成加密链接
     * 
     * @return
     */
    public String getLink() {
        String sig = StringUtil.toHexString(HashUtil.hashMD5(String.valueOf(getId() + getCreated().getTime())));
        return sig.substring(0, 16) + getId() + sig.substring(16);
    }

    /**
     * 根据链接解析ID
     * 
     * @param link
     * @return
     */
    public static Integer parseLink(String link) {

        if (link == null || link.length() < 33) {
            return null;
        }
        String idStr = link.substring(16, link.length() - 16);
        try {
            return Integer.parseInt(idStr);
        } catch (NumberFormatException e) {
        }

        return null;
    }
}
